import read_file from '@dfeidao/atom-mobile/fs/read-file';
import upload from '@dfeidao/atom-mobile/fs/upload';
import { IFeidaoAiMobile } from '@dfeidao/atom-mobile/interfaces';
import get from '@dfeidao/atom-mobile/local/get';

export default async function a002(fd: IFeidaoAiMobile) {
	const img = get(fd, 'img') as string;
	// const img64 = await read_file('file:///storage/emulated/0/Pictures/image-6b9b8546-2032-4c3d-a641-28a9f0076807-1939529582.jpg', 'base64');
	// create an array of objects of the files you want to upload
	console.log(img);
	const files = [
		{
			name: 'feidao',
			filename: 'image-6b9b8546-2032-4c3d-a641-28a9f0076807-1939529582.jpg',
			filepath: 'file:///storage/emulated/0/Pictures/image-6b9b8546-2032-4c3d-a641-28a9f0076807-1939529582.jpg',
			filetype: 'image/jpeg'
		}
	];
	const res = await upload(fd, {
		files,
		toUrl: 'http://192.168.40.196/fsweb/upload?productid=teach_sys',
		method: 'POST',
		headers: {
			'Accept': 'application/json'
		}
	}, 'a003', 'a004');


	// const body = JSON.stringify({
	// 	file_name: 'mobile-test.jpeg',
	// 	file_string: img64
	// });
	// console.log('=============', body);
	// const res = await fetch('http://192.168.40.196/fsweb/upload?productid=by_jxc', {
	// 	body,
	// 	headers: {
	// 		'Content-Type': 'text/json; charset=utf-8'
	// 	},
	// 	method: 'POST'
	// });

	console.log('=====+>>>>>>>>>>>>>>>>>>>>>>', res);
}
